import javax.swing.JPanel;

import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.Component;
import javax.swing.Box;
import javax.swing.JTextArea;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JComboBox;



public class EditPatientGUI extends JPanel {
    User user = new User();
    int location;
    String name;
    String phone;
    String pharmacy;
    String address;
    String insurance;
    String allergies;
    String cell;
    
    
    private JTextField textField;
    private JTextField textField_1;
    private JTextField textField_2;
    private JTextField textField_3;
    private JTextField textField_4;
    private JTextField textField_5;
    private JTextField textField_6;
    private JTextField textField_7;
    private JTextField textField_8;
    public EditPatientGUI() {
        setLayout(null);
        
        
        
        JLabel lblName = new JLabel("Name");
        lblName.setBounds(12, 8, 118, 14);
        add(lblName);
        
        textField = new JTextField();
        textField.setBounds(140, 5, 86, 20);
        add(textField);
        textField.setColumns(10);
        
        JLabel lblAddress = new JLabel("Address");
        lblAddress.setBounds(236, 8, 79, 14);
        add(lblAddress);
        
        textField_1 = new JTextField();
        textField_1.setBounds(325, 5, 86, 20);
        add(textField_1);
        textField_1.setColumns(10);
        
        JLabel lblNewLabel = new JLabel("Phone");
        lblNewLabel.setBounds(9, 33, 121, 14);
        add(lblNewLabel);
        
        textField_2 = new JTextField();
        textField_2.setBounds(140, 30, 86, 20);
        add(textField_2);
        textField_2.setColumns(10);
        
        JLabel lblCell = new JLabel("Cell");
        lblCell.setBounds(246, 33, 69, 14);
        add(lblCell);
        
        textField_3 = new JTextField();
        textField_3.setBounds(325, 30, 86, 20);
        add(textField_3);
        textField_3.setColumns(10);
        
        JLabel lblEmail = new JLabel("Email");
        lblEmail.setBounds(15, 58, 115, 14);
        add(lblEmail);
        
        textField_4 = new JTextField();
        textField_4.setBounds(140, 55, 86, 20);
        add(textField_4);
        textField_4.setColumns(10);
        
        JLabel lblNewLabel_1 = new JLabel("Gender");
        lblNewLabel_1.setBounds(240, 58, 75, 14);
        add(lblNewLabel_1);
        
        textField_5 = new JTextField();
        textField_5.setBounds(325, 55, 86, 20);
        add(textField_5);
        textField_5.setColumns(10);
        
        JLabel lblNewLabel_2 = new JLabel("Pharmacy");
        lblNewLabel_2.setBounds(10, 83, 120, 14);
        add(lblNewLabel_2);
        
        textField_6 = new JTextField();
        textField_6.setBounds(140, 80, 86, 20);
        add(textField_6);
        textField_6.setColumns(10);
        
        JLabel lblInsurance = new JLabel("Insurance");
        lblInsurance.setBounds(242, 83, 75, 14);
        add(lblInsurance);
        
        textField_7 = new JTextField();
        textField_7.setBounds(325, 80, 86, 20);
        add(textField_7);
        textField_7.setColumns(10);
        
        
        
        JLabel lblAllergies = new JLabel("Allergies");
        lblAllergies.setBounds(6, 127, 69, 14);
        add(lblAllergies);
        
        JButton btnCreate = new JButton("Edit");
        btnCreate.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                
                user.setAddress(textField_1.getText());
                user.setAllergies(textField_8.getText());
                user.setInsurance(textField_7.getText());
                user.setEmail(textField_4.getText());
                user.setCellPhone(textField_3.getText());
                user.setPhone(textField_2.getText());
                user.setName(textField.getText());
                user.setPharmacy(textField_6.getText());
                String gen = textField_5.getText();
                if ("MALE".equals(gen)){
                	user.setGender(Gender.MALE);
                }
                else if ("FEMALE".equals(gen)){
                	user.setGender(Gender.FEMALE);
                }
                else{
                	user.setGender(Gender.NULL);
                }
                
                location = 3;
                
            }
        });
        btnCreate.setBounds(41, 211, 89, 23);
        add(btnCreate);
        
        JButton btnCancel = new JButton("Cancel");
        btnCancel.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                location = -1;
            }
        });
        btnCancel.setBounds(186, 211, 89, 23);
        add(btnCancel);
        
        JButton btnNewButton = new JButton("Delete Patient");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                location = -4;
            }
        });
        btnNewButton.setBounds(9, 277, 139, 23);
        add(btnNewButton);
        
        textField_8 = new JTextField();
        textField_8.setColumns(10);
        textField_8.setBounds(76, 127, 282, 57);
        add(textField_8);
    }
    public int getLoc()
    {
        return location;
    }
    public void setLoc(int i)
    {
        location = i;
    }
    public void setUser(User input)
    {
        user = input;
    }
    public User getUser()
    {
        return user;
    }
    
    public void act()
    {
    	System.out.println("Ran");
        textField_1.setText(user.getAddress());
        textField_8.setText(user.getAllergies());
        textField_7.setText(user.getInsurance());
        textField_4.setText(user.getEmail());
        textField_3.setText(user.getCellPhone());
        textField_2.setText(user.getPhone());
        textField.setText(user.getName());
        textField_6.setText(user.getPharmacy());
        textField_8.setText(user.getAllergies());
        textField_5.setText(user.getGender().toString());
        
    }
}
